package com.example.config;

import com.gitee.loyo.Result;
import com.gitee.loyo.config.ChargeProperties;
import com.gitee.loyo.err.SignVerifyFailureException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.annotation.Resource;


@Slf4j
@RestControllerAdvice
public class ExceptionAdvice {
    @Resource
    ChargeProperties chargeProperties;

    @ExceptionHandler(SignVerifyFailureException.class)
    public Result<?> handleSignVerifyFailureException(SignVerifyFailureException e) {
        log.error("SignVerifyFailureException", e);
        Result result = new Result();
        result.setRet(4001);
        result.setMsg("签名校验失败");
        return result.encryptAndSign(
            chargeProperties.getOperatorId(),
            chargeProperties.getDataSecretIV(),
            chargeProperties.getDataSecret(),
            chargeProperties.getSigSecret(),
            o -> o
        );
    }

//    @ExceptionHandler(QueryTokenFailureException.class)
//    public Result<?> handleQueryTokenFailureException(QueryTokenFailureException e) {
//        log.error("QueryTokenFailureException", e);
//        Result result = new Result();
//        result.setRet(4001);
//        result.setMsg("签名校验失败");
//        return result.encryptAndSign(
//            chargeProperties.getOperatorId(),
//            chargeProperties.getDataSecretIV(),
//            chargeProperties.getDataSecret(),
//            chargeProperties.getSigSecret(),
//            o -> o
//        );
//    }
//
//    @ExceptionHandler(RequestFailureException.class)
//    public Result<?> handleRequestFailureException(RequestFailureException e) {
//        log.error("RequestFailureException", e);
//        Result result = new Result();
//        result.setRet(4001);
//        result.setMsg("签名校验失败");
//        return result.encryptAndSign(
//            chargeProperties.getOperatorId(),
//            chargeProperties.getDataSecretIV(),
//            chargeProperties.getDataSecret(),
//            chargeProperties.getSigSecret(),
//            o -> o
//        );
//    }
}
